<?php

namespace App\Http\Requests\client;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait OpenInfoRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'mobile' => 'required',
            'wechat' => 'required',
            'email' => 'required|email',
        ], [
            'mobile.required' => '请填写电话',
            'wechat.required' => '请填写微信',
            'email.required' => '请填写邮箱',
            'email.email' => '请填写正确格式的邮箱',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
